package com.source.configure;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.function.Predicate;

@Configuration
@EnableSwagger2WebMvc
@EnableKnife4j
public class SwaggerConfiguration {

    @Value("${spring.application.name}")
    private String applicationName;

    @Bean(value = "defaultApi")
    public Docket defaultApi2() {
        Predicate<RequestHandler> apiPackage = RequestHandlerSelectors.basePackage("com.source.controller");

        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .version("1.0")
                        .title(applicationName + " 文档中心")
                        .description("<div style='font-size:15px;'>" + applicationName + " RESTful APIs</div>")
                        .build())
                //分组名称
                .groupName("2.X版本")
                .select()
                //这里指定Controller扫描包路径
                .apis(apiPackage)
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

}